﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Planisoft.Entities;
using Planisoft.BL;
using Microsoft.Practices.Unity;

namespace Planisoft.ClienteMvcWeb.Controllers
{
    public class RegPensionarioController : Controller
    {
        [Dependency]
        public IRegPensionarioBL RegPensionarioBL { get; set; }
        [Dependency]
        public IValoRegPensionarioBL ValoRegPensionarioBL { get; set; }
        [Dependency]
        public IValRegPensCabBL ValRegPensCabBL{ get; set; }
        [Dependency]
        public IMesBL MesBL { get; set; }
        //
        // GET: /RegPensionario/

        public ActionResult ListarRegPens()
        {
            
            var lista1 = ValRegPensCabBL.GetByGroupRegPensionario();    
            return View(lista1);
        }
        
        public ActionResult Index()
        {
            var listMesAfp = MesBL.GetAllFromMesAfp();
            ViewData["IdMes"] = new SelectList(listMesAfp, "IdMes", "DescMes");

            var lista = RegPensionarioBL.GetAllFromRegPensionario();
            return View(lista);
        }

        [HttpPost]
        public ActionResult valoresRegPensionario(Int32 id, Int32 fondoAfp, Int32 comisionAfp, Int32 primaAfp, string AnioAfp, string MesAfp) 
        {
            ValoRegPensionarioBL.AddValorRegPensionario(id,fondoAfp,comisionAfp,primaAfp,AnioAfp,MesAfp);

            //var msg = new { exito = true, msg = "Planilla Generada, par el trabajador: " + id.ToString() };
            //return Json(msg, JsonRequestBehavior.AllowGet);
            //ValoRegPensionarioBL.AddValorRegPensionario(valoresRegPensionario);
            return RedirectToAction("ListarRegPens");
        }

        
        //
        // GET: /RegPensionario/Details/5

        public ActionResult Details(int id)
        {
            var lista = ValoRegPensionarioBL.GetAllFromRegPensionarioByPeriodo(id);
            return View(lista);
        }

        //
        // GET: /RegPensionario/Create

        public ActionResult Create()
        {
            return View();
            
        } 

        //
        // POST: /RegPensionario/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /RegPensionario/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /RegPensionario/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /RegPensionario/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /RegPensionario/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
